﻿using System;
using System.Globalization;

namespace UsefulTools.cly   // 改成自己的命名空间
{
    public class DateTimeUtil
    {
        private DateTime CurrentTime;

        public DateTimeUtil()
        {
            CurrentTime = DateTime.Now;
        }

        public int Year => CurrentTime.Year;
        public int Month => CurrentTime.Month;
        public int Week => CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(CurrentTime, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
        public int Day => CurrentTime.Day;

        public string GetCurrentTime() => CurrentTime.ToString("yyyy-MM-dd HH:mm:ss");

        /// <summary>
        /// 格式化时间
        /// </summary>
        /// <param name="format">格式 如：yyyy-MM-dd</param>
        /// <returns></returns>
        public string FormatTime(string format)
        {
            return CurrentTime.ToString(format);
        }
    }
}
